package dse.modules.eln;

import java.util.Collection;
import java.util.Vector;
import java.io.Serializable;

import dse.Cluster;
import dse.Network;
import dse.Node;

public class EarthLikeNetwork extends Network implements Serializable
{
	private static final long serialVersionUID = 1L;
	private int width;
	private int height;
	private Vector<NodeWithCoordinates> nodes;
	private Vector<Cluster> clusters;
	
	public EarthLikeNetwork (int width, int height, int numberOfNodes) {
		this.width = width;
		this.height = height;
		this.nodes = new Vector<NodeWithCoordinates>(numberOfNodes);
		this.clusters = new Vector<Cluster>();
	}
	
	
	public int getWidth () { return width; }
	public int getHeight () { return height; }
	
	
	/**
	 * Adds a new node.
	 * @param nwc
	 */
	public void addNode (NodeWithCoordinates nwc) {
		assert(nodes.size() == nwc.id() - 1);
		nodes.add(nwc);
	}
	/**
	 * Adds a new cluster.
	 * @param cluster
	 */
	public void addCluster (Cluster cluster) {
		assert(clusters.size() == cluster.id() - 1);
		clusters.add(cluster);
	}
	
	/**
	 * We can speed this up here. 
	 */
	public Node lookupNode (int id) {
		// We assume that id's are indicies into the array/vector
		return nodes.elementAt(id-1);
	}
	/**
	 * Go through all nodes in the network.
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes"})
	public Collection<Node> nodes () {
		return (Collection)nodes;
	}
	/**
	 * Returns the number of nodes in the network.
	 * @return
	 */
	public int nodeCount () {
		return nodes.size();
	}
	/**
	 * Gets the maximum id of all nodes in the network.  This is useful for 
	 * hashing.
	 * @return
	 */
	public int maxNodeId () {
		return nodes.size();
	}
	/**
	 * Finds and returns the cluster with the given id.
	 * 
	 * @param id
	 * @return
	 */
	public Cluster lookupCluster (int id) {
		return clusters.elementAt(id-1);
	}
	/**
	 * Go through all clusters in the network.
	 * @return
	 */
	public Iterable<Cluster> clusters () {
		return clusters;
	}
	/**
	 * Whether or not the network has clusters.
	 * @return
	 */
	public boolean hasClusters () {		
		return true;
	}
	/**
	 * Returns the number of clusters in the network.
	 * @return
	 */
	public int clusterCount () {
		return clusters.size();
	}
	/**
	 * Gets the maximum id of all clusters in the network.  This is useful for 
	 * hashing.
	 * @return
	 */
	public int maxClusterId () {
		return clusters.size();
	}
}
